﻿@model  Logic.Models.TaskCreateModel

@{
    Layout = Logic.ViewConfiguration.GetViewConfig().Tasks_Create_Layout;
    ViewBag.Title = "Create Task";
}

@{Html.RenderPartial("_formCreate");}
<script>
    function getCustomFields()
    {
        var label = $('.CustomContainer .Label');
        

        if ($('.customField').length != 0)
        {
            label.html(label.html().replace("-", "+"));
            $('#CustomFields').html('');
            return;
        }



        var renderFields = function (values) {
            getCustomFields.fields = values;
            label.html(label.html().replace("+", "-"));
            var row;
            for (var i = 0; i < values.length; i++) {
                if (i % 3 == 0) {
                    row = $('<div class="Row">');
                    $("#CustomFields").append(row);
                }

                var fieldName = stringFormat("CustomFields[{0}]", i);
                var inputs = new window["T_" + values[i].TypeName]().getControls(values[i].Name, fieldName, "", null, null, values[i].R_Type);

                var prop = $(stringFormat("<div class='Property MediumColumn {0}'>", i % 3 == 0 ? "Right" : i % 3 == 1 ? "Middle" : ""));
                row.append(prop);

                prop.append(stringFormat("<div class='customField'>\
                        <div class='Label'>{0}</div>\
                    </div>", [values[i].Name]));
                prop.find('.customField').append(inputs);

            }

            AttachEvents($("#CustomFields"));
            var pos = $(".CustomContainer").position().top + $(".Info_Container").scrollTop();
            $('.Info_Container').scrollTop(pos);

        };
        if (getCustomFields.fields)
            renderFields(getCustomFields.fields);
        else
        {
            $("#CustomFields").css({ height: 70 }).show_loading(true);
            getCustomFields.count = getCustomFields.count ? getCustomFields.count + 1 : 1;
            var count = getCustomFields.count;

            remoteRequest({
                url: '@(Logic.Constants.CurrentUrl)/tasks/customFields',
                contentType: "JSON",
                type: "POST",
                success: function (data) {
                    if (getCustomFields.count == count) {
                        $("#CustomFields").css("height", "").show_loading(false);
                        renderFields(data);
                    }
                }
            });
        }
    }
    
    $('#CustomFieldsLink').click(getCustomFields);

    $(document).ready(function ()
    {
        $('#Resources').remove();
    });
</script>